package com.qf.flower_zuul.controller;

import com.qf.flower_zuul.entity.JsonResult;
import com.qf.flower_zuul.service.FlowersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

import static com.qf.flower_zuul.entity.JsonResult.createSuccessJsonResult;

@RestController
@RequestMapping("/flower")
public class FlowersController {

    @Autowired
    private FlowersService flowersService;


    @RequestMapping("/index")
    public JsonResult findBySubarea(@RequestParam(value = "subarea") String subarea) {
        List<Object> objects = new ArrayList<>();

        JsonResult jsonResult = flowersService.findBySubarea("爱情鲜花专区");
        Object flowera = jsonResult.getResultData();
        objects.add(flowera);

        JsonResult jsonResults = flowersService.findBySubarea("生日鲜花专区");
        Object flowers = jsonResults.getResultData();
        objects.add(flowers);

        JsonResult jsonResulh = flowersService.findBySubarea("精致礼盒花");
        Object flowerh = jsonResulh.getResultData();
        objects.add(flowerh);

        JsonResult jsonResulk = flowersService.findBySubarea("开业花篮专区");
        Object flowerk = jsonResulk.getResultData();
        objects.add(flowerk);

        JsonResult jsonResull = flowersService.findBySubarea("绿色植物专区");
        Object flowerl = jsonResull.getResultData();
        objects.add(flowerl);

        JsonResult jsonResuly = flowersService.findBySubarea("永生花专区");
        Object flowery = jsonResuly.getResultData();
        objects.add(flowery);

        return createSuccessJsonResult(objects);
    }

    @RequestMapping("/select")
    public JsonResult findByNameAndType(@RequestParam(value = "detailId") Long detailId, @RequestParam(value = "flowerName") String flowerName) {
        if (detailId == 0) {
            detailId = null;
        }

        JsonResult flowers = flowersService.findByNameAndId(detailId, flowerName);
        return flowers;
    }


}
